package com.sgb.kjwl.view.widget;

import android.content.Context;

import androidx.recyclerview.widget.RecyclerView;

import com.sgb.kjwl.R;
import com.sgb.link.view.widget.XLinearLayoutManager;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.link.view.adapter.PickAdapter;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;

import java.util.List;

public class PickPopWindow1 extends BasePopWindow {

    private RecyclerView recyclerView;
    private PickAdapter pickAdapter;

    public PickPopWindow1(Context context) {
        super(context);
    }

    @Override
    protected int popLayout() {
        return R.layout.popwindow_filter_packers_1;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        recyclerView = holder.getPop().findViewById(R.id.rlv_list);


        holder.getPop().findViewById(R.id.empty_view).setOnClickListener(v -> dismiss());

        if (pickAdapter == null) {
            pickAdapter = new PickAdapter(mContext, null, R.layout.item_pick_filter_child_3);
        }
        pickAdapter.setItemSelect(true);
        pickAdapter.setDefItem(0);
        XLinearLayoutManager manager = new XLinearLayoutManager(mContext);
        recyclerView.setLayoutManager(manager);
        recyclerView.setAdapter(pickAdapter);

        pickAdapter.setOnItemClick(new AdapterOnItemClick<PickSelectEntity>() {
            @Override
            public void onItemClick(PickSelectEntity pickSelectEntity, int position) {
                String no = pickSelectEntity.getNo();
                String name = pickSelectEntity.getProjectscale();
                if (onResultClick != null) {
                    onResultClick.result(no, name, position);
                }
                dissMiss();
            }
        });
    }

    public void setData(List<PickSelectEntity> list) {
        pickAdapter.setDatas(list);
    }

    public void setDefItem(int position){
        pickAdapter.setDefItem(position);
    }

    private OnResultClick onResultClick;

    public void setDefaultItem(int i) {
        pickAdapter.setDefItem(i);
        pickAdapter.setCheckDefault(i);
    }

    public interface OnResultClick {
        void result(Object key1, Object key2, Object key3);
    }

    public void setOnResultClick(OnResultClick onResultClick) {
        this.onResultClick = onResultClick;
    }
}
